## DESCRIPTION
## Trigonometry: proving trig identities
## ENDDESCRIPTION

## KEYWORDS('trigonometry', 'proving trig identities')

## DBsubject('WeBWorK')
## DBchapter('WeBWorK Tutorial')
## DBsection('Fort Lewis Tutorial 2011')
## Date('01/30/2011')
## Author('Paul Pearson')
## Institution('Fort Lewis College')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')


DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;


###################################
#  Setup

Context("Numeric")->variables->are(t=>"Real");

#
#  Redefine the sin(x) to be e^(pi x)
#
Context()->functions->remove("sin");
package NewFunc;
# this next line makes the function a 
# function from reals to reals
our @ISA = qw(Parser::Function::numeric);
sub sin {
  shift; my $x = shift;
  return CORE::exp($x*3.1415926535);
}
package main;
# Make it work on formulas as well as numbers
#sub cos {Parser::Function->call('cos',@_)} # if uncommented, this line will generate error messages
#  Add the new functions to the Context
Context()->functions->add( sin => {class => 'NewFunc', TeX => '\sin'}, );


#
#  You manually define the answers
#
@answers = ();
$answers[1] = Formula("1-cos(t)");
$answers[2] = Formula("sin(t)");
$answers[3] = Formula("1-(cos(t))^2");


#
#  Automatic configuration for answer evaluation
#
@ans_eval = ();
@scores = ();
foreach my $i (1..$#answers) {
  $ans_eval[$i] = $answers[$i] ->cmp();
  $ans_hash[$i] = $ans_eval[$i]->evaluate($inputs_ref->{ANS_NUM_TO_NAME($i)});
  $scores[$i]   = $ans_hash[$i]->{score};
}


###########################################
#  Main text and answer evaluation part 1

Context()->texStrings;
BEGIN_TEXT
${BBOLD}Part 1 of 3:${EBOLD}
$BR
$BR
In this multi-part problem, we will use algebra to verify 
the identity
$BCENTER
\( \displaystyle \frac{ \sin(t) }{ 1-\cos(t) } = \frac{ 1+\cos(t) }{ \sin(t) }. \)
$ECENTER
$BR
First, using algebra we may rewrite the equation above as
$BR
$BR
\( \displaystyle \sin(t) = \left( \frac{1+\cos(t)}{\sin(t)} \right) \cdot \Big( \)
\{ ans_rule(20) \}
\( \Big) \) 
END_TEXT
Context()->normalStrings;

ANS( $ans_eval[1] );



##########################################
#  Main text and answer evaluation part 2

if ($scores[1]==1) {

Context()->texStrings;
BEGIN_TEXT
$PAR
$HR
${BBOLD}Part 2 of 3:${EBOLD} 
$BR
$BR
Then, using algebra we may rewrite the equation as
$BR
$BR
\( \sin(t) \cdot \big( \)
\{ ans_rule(20) \}
\( \big) = \big(1+\cos(t)\big) \cdot \big(1-\cos(t)\big) \),
END_TEXT
Context()->normalStrings;

ANS( $ans_eval[2] );

}  # end if

 
##########################################
#  Main text and answer evaluation part 3

if ( ($scores[1]==1) && ($scores[2]==1) ) {

Context()->texStrings;
BEGIN_TEXT
$PAR
$HR
${BBOLD}Part 3 of 3:${EBOLD} 
$BR
$BR
Finally, using algebra we may rewrite the equation as
$BR
$BR
\( \sin^2(t) = \)
\{ ans_rule(20) \}
$BR
$BR
which is true since \( \cos^2(t) + \sin^2(t) = 1 \).
Thus, the original identity can be derived 
by reversing these steps.
END_TEXT
Context()->normalStrings;

ANS( $ans_eval[3] );

}  # end if


COMMENT("MathObject version.  This is a multi-part problem 
in which the next part is revealed only after the previous 
part is correct.  Prevents students from entering trivial 
identities (entering what they were given)");

ENDDOCUMENT();